import ktor.KtorUserDataSource
import models.User
import models.UserRepository

class UserRepositoryImpl(
    private val ktorUserDataSource: KtorUserDataSource
) : UserRepository {
    override suspend fun me(): Result<User> {
        return ktorUserDataSource.me().checkNullAndGet()
    }

    override fun logout() {
        ktorUserDataSource.logout()
    }

    override suspend fun users(): Result<List<User>> {
        return ktorUserDataSource.users().checkNullAndGet()
    }

    override suspend fun user(id: Int): Result<User> {
        return ktorUserDataSource.user(id).checkNullAndGet()
    }

    override suspend fun delete(id: Int): Result<Boolean> {
        return ktorUserDataSource.delete(id).checkNull()
    }

    override suspend fun updateRole(id: Int, role: String): Result<Boolean> {
        return ktorUserDataSource.updateUser(id, role = role).checkNull()
    }

    override suspend fun updateLocation(id: Int, locationId: Int): Result<Boolean> {
        return ktorUserDataSource.updateUser(id, locationId = locationId).checkNull()
    }
}